package map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
import java.util.Set;

public class HashMapDemo2 {
	public static void main(String[] args) {
		HashMap<String,Integer> scores = new HashMap<>();
		scores.put("建宇", 20);
		scores.put("世宇", 21);
		scores.put("智斌", 61);
		scores.put("乃生", 99);
		
		//1.遍历  Entry就是一条 {建宇=20}
		Set<Entry<String, Integer>> entrys = scores.entrySet();
		//使用迭代器遍历set集合
		Iterator<Entry<String, Integer>> it = entrys.iterator();
		while(it.hasNext()) {
			Entry<String, Integer> entry = it.next();
			System.out.println(entry.getKey() + ":" + entry.getValue());
			
		}
		System.out.println("------------------------------");
		//2.forEach
		scores.forEach(new BiConsumer<String, Integer>() {
			@Override
			public void accept(String t, Integer u) {
				System.out.println(t + ":" + u);
			}
		});
	}
}
